/**
    \file ksc_to_unicode.c

    COPYRIGHT(C) 2011,ShenZhen JiuZhou CO.,LTD. \n
    All rights reserved. \n\n

    \brief implement the charset interface.

    \details charset interface includes:
        -
    \version 1.1
    \date 2011-05-10
    \author jiaolizhi <jiaolizhi@aaa.com>
    \note Created

    \version 1.0
    \date 2009-03-03
    \author yangfeng <yangfeng@aaa.com>
    \note Created
*/

/* Includes --------------------------------------------------------------- */
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "usm_typedef.h"

#include "usm_charset.h"
#include "ksc_to_unicode.h"


/* Private Macros --------------------------------------------------------- */

/* Private Types ---------------------------------------------------------- */

/* Private Constants ------------------------------------------------------ */

/* Private Variables (static) --------------------------------------------- ----*/

/* Global Variables ------------------------------------------------------- */

/* Private Function prototypes -------------------------------------------- --*/

/* Functions -------------------------------------------------------------*/

/**
    \fn JZ_Error_t USM_CS_KSC2Unicode(JZ_WCHAR *pwszDest, const JZ_CHAR *pszSrc, JZ_INT32 nLength)

    \brief Converts a KSC string into a Unicode string.

    \param[out] pwszDest The destination wide-character string.
    \param[in] pszSrc The source string which charset format is KSC.
    \param[in] nLength The length of the source string. The value of 0 represents the source string ends with a null character.

    \retval JZ_SUCCESS Successful.
    \retval JZ_FAILURE Failed.
    \retval JZ_ERROR_BAD_PARAMETER Bad parameter passed.

    \remark

    \see USM_CS_Unicode2KSC
*/
JZ_Error_t USM_CS_KSC2Unicode(JZ_WCHAR *pwszDest, const JZ_CHAR *pszSrc, JZ_INT32 nLength)
{
	JZ_UINT16  nTemp;
	JZ_UINT16  nIndex = 0;


	while (*pszSrc)
	{

		if (*pszSrc& 0x80)
		{
			USM_CS_GetMatchedCode(ksc_to_unicode_table, KSC_SIZE,(((pszSrc[0]) << 8) & 0xff00) + (pszSrc[1] & 0xff), &nTemp);

			pwszDest[nIndex] = nTemp;
			pszSrc += 2;
		}
		else
		{
			pwszDest[nIndex] = (JZ_UINT16) (*pszSrc);
			pszSrc += 1;
		}

		nIndex++;
	}

	pwszDest[nIndex] = 0x00;

	return(JZ_SUCCESS);

}


